The Structure of Continuation - Passing StylesbyJohn
نویسنده
چکیده
Continuation-passing style (CPS) is a method of representing program evaluation order in a purely functional manner. Many applications of CPS rely on CPS transformations which explicitly encode evaluation strategies (e.g., call-by-name, call-by-value, etc.) into the structure of programs. Existing CPS transformations are based almost entirely on the call-by-name and call-by-value CPS transformations de ned by Plotkin, Reynolds, and Fischer over twenty years ago. These transformations introduce the same pattern of evaluation (either call-by-name or call-by-value) throughout the entire program. Such rigidness ignores additional computational properties such as strictness and termination that are used to optimize program evaluation. We take a more general approach to CPS | we direct CPS transformations by computational properties instead of by xed evaluation strategies. For example, a CPS transformation directed by strictness properties subsumes both the call-by-name transformation (in case all functions are non-strict) and the call-by-value transformation (in case all functions are strict). Moreover, it can transform programs with both strict and nonstrict functions such as a call-by-name program after strictness analysis. Considering termination properties allows CPS transformations to avoid introducing unnecessary continuations. Based on the property of value, we show how CPS transformations (e.g., the strictness-directed transformation) can be factored into the callby-value transformation and a \thunk"-based transformation. This simpli es reasoning about the factored transformations. To formalize the approach, extensions of traditional -calculi are proposed to capture strictness and termination properties. Our general CPS transformations translate the extended calculi into the standard and v calculi. The transformations are shown to preserve operational semantics and equational properties of the extended languages. As a result, we obtain a variety of CPS transformations which have applications to compilation and partial evaluation. Standard CPS transformations (as well as the new ones presented here) have striking structural similarities. However, these similarities have never been exploited since previous work has always dealt with each transformation separately. To remedy this, we propose a generic framework for studying CPS transformations based on Moggi's computational meta-language. The framework captures the essence of the structure of continuationpassing styles and allows generic formalizations of CPS transformations, proofs of preservation of operational semantics and program calculi, optimizations known as \administrative reductions", typing properties, and inverse transformations. Results for speci c evaluation orders follow as corollaries of the generic results. Because the extended type system of the meta-language directly captures computational properties, we can describe all aspects of the standard call-by-value and call-by-name CPS transformations as well as the variations presented in the rst part of the dissertation. Thus, previous work on CPS and CPS transformations is uni ed in a single framework. 1 Acknowledgements Olivier Danvy deserves my warmest gratitude for supervising this work. His concern and attention to my progress were extraordinary | he continues to be a mentor and true friend. Olivier and I were co-authors of several papers which form the core of this dissertation and his ideas were the genesis of many of the results presented here. Dave Schmidt served as my co-supervisor and his wisdom was invaluable. He and Allen Stoughton provided important technical advice at various stages of this work. I thank Olivier, Dave, and Allen for their nancial support of my studies. The good fellowship of the programming language group at Kansas State University has made my stay in Kansas a very enjoyable experience. In particular, I wish to thank my o ce partner Sergey Kotov for his careful proofreading, keen criticism, his encouraging suggestions. Andrzej Filinski and Julia Lawall provided valuable feedback and advice at various stages of this work. Their work on continuations also provided inspiration. Finally, I thank my wife Lorie for her long-su ering patience, warm encouragement, and delicious apple pies. 2
منابع مشابه
Memoisation: Purely, Left-recursively, and with (Continuation Passing) Style
Memoisation, or tabling, is a well-known technique that yields large improvements in the performance of some recursive computations. Tabled resolution in Prologs such as XSB and B-Prolog can transform so called left-recursive predicates from non-terminating computations into finite and well-behaved ones. In the functional programming literature, memoisation has usually been implemented in a way...
متن کاملParallel Continuation-Passing Style A Compiler Representation for Incremental Parallelization
We present a parallel version of continuation passing style, called pCPS. Using pCPS as the intermediate representation allows a compiler to first translate a sequential program into a form with explicit scheduling and then gradually increase the parallelism by removing happens-before constraints whenever possible.
متن کاملOn the Overhead of CPS
Continuation-passing style (CPS) is often criticized to be more expensive than the usual direct style of functional programming. By structure, CPS functions indeed are passed one extra argument (the continuation), and each intermediate result indeed occurs in a function call (to the continuation). As higher-order functions, continuations are also more expensive. However, by structure also, CPS ...
متن کاملContinuation Passing for C A space-efficient implementation of concurrency
Threads are a convenient abstraction for programming concurrent systems. They are however expensive, which leads many programmers to use coarse-grained concurrency where a fine-grained structure would be preferable, or use more cumbersome implementation techniques. Cooperative threads can be easily implemented in a language that provides first-class continuations. Unfortunately, CPS conversion,...
متن کاملRetraction Approach to CPS Transform
We study the continuation passing style (CPS) transform and its generalization, the computational transform, in which the notion of computation is generalized from continuation passing to an arbitrary one. To establish a relation between direct style and continuation passing style interpretation of sequential call-by-value programs, we prove the Retraction Theorem which says that a lambda term ...
متن کاملComplete Call-by-Value Calculi of Control Operators, I
We give new call-by-value calculi of control operators that are complete for the continuation-passing style semantics. Various anticipated computational properties are induced from the completeness. In the first part of a series of papers, we give the characterization of termination properties using the continuation-passing style semantics as well as the union-intersection type discipline.
متن کامل